/**
* @author zqp
* @version2017年12月24日 
* @description 
*/
package com.zqp.security.core.social.qq.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;

import com.zqp.security.core.properties.QQProperties;
import com.zqp.security.core.properties.SecurityProperties;
import com.zqp.security.core.social.qq.connet.QQconnectionFactory;

/**
* @author zqp
* @version2017年12月24日 
* @description 
*/
@Configuration
@ConditionalOnProperty(prefix="zqp.security.social.qq",name="app-id")
public class QQAutoConfig extends SocialAutoConfigurerAdapter {
	@Autowired
	private DataSource dataSource;
	@Autowired
	private SecurityProperties securityProperties;

	/* (non-Javadoc)
	 * @see org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter#createConnectionFactory()
	 */
	@Override
	protected ConnectionFactory<?> createConnectionFactory() {
		QQProperties qq = securityProperties.getSocial().getQq();
		return  new  QQconnectionFactory(qq.getProviderId(), qq.getAppId(), qq.getAppSecret());

	}
	

	@Override
	public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
		
		JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource,
				connectionFactoryLocator, Encryptors.noOpText());
		repository.setTablePrefix("zqp_");
//		if (connectionSignUp != null) {
//			repository.setConnectionSignUp(connectionSignUp);
//		}
		return repository;
	}

}
